package com.study.thread.aqs;

public class AqsDemo {
    private static Mutex lock = new Mutex();

    public static void main(String[] args) {
        new Thread(() -> {
            lock.lock();
            System.out.println(Thread.currentThread().getName() + "：开始启动");
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            printLock();
            System.out.println(Thread.currentThread().getName() + "：准备结束");
            lock.unlock();
        }).start();

        new Thread(() -> {
            lock.lock();
            System.out.println(Thread.currentThread().getName() + "：开始启动");
            System.out.println(Thread.currentThread().getName() + "：准备结束");
            lock.unlock();
        }).start();
    }

    public static void printLock() {
        lock.lock();
        System.out.println("进入Lock");
        lock.unlock();
    }
}
